package net.maku.biz.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.AllArgsConstructor;
import net.maku.biz.convert.BizLegalAidConvert;
import net.maku.biz.dao.BizLegalAidDao;
import net.maku.biz.entity.BizLegalAidEntity;
import net.maku.biz.query.BizLegalAidQuery;
import net.maku.biz.service.BizLegalAidService;
import net.maku.biz.vo.BizLegalAidVO;
import net.maku.framework.common.utils.PageResult;
import net.maku.framework.mybatis.service.impl.BaseServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/**
 * 法律援助
 *
 * @author 阿沐 babamu@126.com
 * @since 1.0.0 2025-03-30
 */
@Service
@AllArgsConstructor
public class BizLegalAidServiceImpl extends BaseServiceImpl<BizLegalAidDao, BizLegalAidEntity> implements BizLegalAidService {



    private final BizLegalAidDao legalAidDao;

    @Override
    public PageResult<BizLegalAidVO> page(BizLegalAidQuery query) {
        IPage<BizLegalAidEntity> page = baseMapper.selectPage(getPage(query), getWrapper(query));
        return new PageResult<>(BizLegalAidConvert.INSTANCE.convertList(page.getRecords()), page.getTotal());
    }

    private LambdaQueryWrapper<BizLegalAidEntity> getWrapper(BizLegalAidQuery query){
        LambdaQueryWrapper<BizLegalAidEntity> wrapper = Wrappers.lambdaQuery();
        return wrapper;
    }

    @Override
    public void save(BizLegalAidVO vo) {
        BizLegalAidEntity entity = BizLegalAidConvert.INSTANCE.convert(vo);
        entity.setCreateTime(new Date());
        baseMapper.insert(entity);
    }

    @Override
    public void update(BizLegalAidVO vo) {
        BizLegalAidEntity entity = BizLegalAidConvert.INSTANCE.convert(vo);

        updateById(entity);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void delete(List<Long> idList) {
        removeByIds(idList);
    }

}